package com.emns.web.mobile;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.emns.pojo.YueduComment;
import com.emns.service.mobile.YueduCommentMobileService;
import common.PageInfo;

@Controller
@RequestMapping(value = "/yueduCommentMobile")
public class YueduCommentMobileController {

	@Autowired
	YueduCommentMobileService ycms;

	// 添加悦读评论数据
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	public void addComment(Model model, YueduComment ydc) {
		ydc.setPublishdate(new Date());
		ydc.setState(1);
		int count = ycms.addYueduComment(ydc);
		String errCode = "";
		String errMsg = "";
		if (count > 0) {
			errCode = "0";
			errMsg = "插入成功";
		} else {
			errCode = "1";
			errMsg = "插入失败";
		}
		model.asMap().remove("yueduComment");
		model.addAttribute("errorCode", errCode);
		model.addAttribute("errorMessage", errMsg);
		model.addAttribute("info", count);
	}

	// 查找分页悦读评论数据
	@RequestMapping(value = "/queryPage")
	public void queryPage(Model model,
			@RequestParam(required = false) Integer pageNo,
			@RequestParam(required = false) Integer pageSize,
			@RequestParam(required = false) Integer yueduId) {
		PageInfo<YueduComment> pageInfo = null;
		String errMsg = "";
		String errCode = "";
		if (pageNo == null || pageSize == null) {
			errCode = "1";
			errMsg = "缺少参数:pageNo或pageSize";
		} else if (yueduId == null) {
			errCode = "1";
			errMsg = "缺少参数:yueduId";
		} else {
			errCode = "0";
			errMsg = "查询成功";
			pageInfo = new PageInfo<YueduComment>();
			pageInfo.setPageNum(pageNo);
			ycms.queryPageAll(yueduId, pageInfo);
		}
		model.addAttribute("errorCode", errCode);
		model.addAttribute("errorMessage", errMsg);
		model.addAttribute("info", pageInfo);
	}

}
